import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { PartialConsult, IllnessForm } from '@/types/consult'
import { ConsultType, IllnessType } from '@/enum'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义数据
    const consult = ref<PartialConsult>({})
    //   定义修改门诊类型方法
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    //   定义修改极速问诊类型(三甲，普通)
    const setIllnessType = (type: IllnessType) => {
      consult.value.illnessType = type
    }
    // 定义存入选择的科室类型的方法
    const setDepId = (id: string) => {
      consult.value.depId = id
    }
    // 定义存病情描述信息方法
    const setIllness = (illnessForm: IllnessForm) => {
      consult.value.illnessDesc = illnessForm.illnessDesc
      consult.value.consultFlag = illnessForm.consultFlag
      consult.value.illnessTime = illnessForm.illnessTime
      consult.value.pictures = illnessForm.pictures
    }
    // 存入选中患者的ID
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }
    // 存入优惠券
    const setCoupon = (couponId: string) => {
      consult.value.couponId = couponId
    }
    //清空仓库数据
    const clearStore = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCoupon,
      clearStore
    }
  },
  {
    persist: true //持久化到本地，创建仓库的第三个参数
  }
)
